package com.huawei.lynnbit.tool.cocos.config;


import com.huawei.lynnbit.tool.cocos.util.JsonUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;

@Data
@Slf4j
public class SystemConfig {
    private String cocosCreator2Path;
    private String cocosCreator3Path;

    private String devEcoInstallPath;

    private String commonDevEcoProject;

    private String output;

    public static SystemConfig newInstance(String filePath) throws IOException {
        String configStr = FileUtils.readFileToString(new File(filePath), Charset.forName("UTF-8"));
        return JsonUtils.toEntity(configStr, SystemConfig.class);
    }

    public boolean isValid() {
        if (StringUtils.isBlank(devEcoInstallPath)) {
            log.error("devEcoInstallPath cannot be blank");
            return false;
        }

        return true;
    }
}
